home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / progem.lzh / rscvmain.c < prev    next >
C/C++ Source or Header  |  1987-06-23  |  15KB  |  723 lines

  1. /*------------------------------*/
  2. /*    includes        */
  3. /*------------------------------*/
  4.  
  5. #include "portab.h"                /* portable coding conv    */
  6. #include "machine.h"                /* machine depndnt conv    */
  7. #include "obdefs.h"                /* object definitions    */
  8. #include "gembind.h"                /* gem binding structs    */
  9. #include "osbind.h"                /* BDOS definitions    */
  10. #include "gemdefs.h"
  11. #include "rsconv.h"
  12.  
  13.  
  14. /*------------------------------*/
  15. /*    defines            */
  16. /*------------------------------*/
  17.  
  18. #define    NIL        -1
  19. #define DESK        0
  20. #define    ARROW        0
  21. #define    HOUR_GLASS    2            
  22. #define END_UPDATE    0
  23. #define    BEG_UPDATE    1
  24.  
  25. typedef struct memform
  26.     {
  27.     WORD        *mp;
  28.     WORD        fwp;
  29.     WORD        fh;
  30.     WORD        fww;
  31.     WORD        ff;
  32.     WORD        np;
  33.     WORD        r1;
  34.     WORD        r2;
  35.     WORD        r3;
  36.     } MFDB;
  37.  
  38. /*------------------------------*/
  39. /*    Global            */
  40. /*------------------------------*/
  41. GLOBAL    WORD    gl_apid;
  42.  
  43. GLOBAL WORD    contrl[11];        /* control inputs        */
  44. GLOBAL WORD    intin[80];        /* max string length        */
  45. GLOBAL WORD    ptsin[256];        /* polygon fill points        */
  46. GLOBAL WORD    intout[45];        /* open workstation output    */
  47. GLOBAL WORD    ptsout[12];
  48.  
  49. GLOBAL    WORD    gl_wchar;        /* character width        */
  50. GLOBAL    WORD    gl_hchar;        /* character height        */
  51. GLOBAL    WORD    gl_wbox;        /* box (cell) width        */
  52. GLOBAL    WORD    gl_hbox;        /* box (cell) height        */
  53. GLOBAL    WORD    gem_handle;        /* GEM handle            */
  54. GLOBAL    WORD    vdi_handle;        /* VDI handle            */
  55. GLOBAL    WORD    work_out[57];        /* open virt workstation values    */
  56. GLOBAL    GRECT    scrn_area;        /* scrn area            */
  57. GLOBAL    MFDB    scrn_mfdb;        /* scrn memory def'n for blt    */
  58. GLOBAL    GRECT    full;            /* desktop size            */
  59.  
  60. /*------------------------------*/
  61. /*    External        */
  62. /*------------------------------*/
  63.  
  64. EXTERN    WORD    desel_obj();
  65.  
  66. /*------------------------------*/
  67. /*    Local            */
  68. /*------------------------------*/
  69.  
  70. MLOCAL    WORD    native_in = TRUE;    /* TRUE: input .RSC is native    */
  71.                     /* FALSE: input .RSC is foreign */
  72. MLOCAL    WORD    conv_def = TRUE;    /* TRUE: convert .DEF also    */
  73. MLOCAL    WORD    new_dfn = FALSE;    /* TRUE: use new symbol fmt    */
  74. MLOCAL    BYTE    old_rsc[4] = "RSC";    /* new resource file extent    */
  75. MLOCAL    BYTE    new_rsc[4] = "RS2";    /* new resource file extent    */
  76. MLOCAL    BYTE    old_def[4] = "DEF";    /* new definition file extend   */
  77. MLOCAL    BYTE    new_def[4] = "DF2";    /* new definition file extend   */
  78. MLOCAL    BYTE    r_file[81];        /* resource file name         */
  79. MLOCAL    BYTE    d_file[81];        /* definition file name     */
  80. MLOCAL    BYTE    r2_file[81];        /* output resource name        */
  81. MLOCAL    BYTE    d2_file[81];        /* output definition name    */
  82. MLOCAL    WORD    r_hndl = -1;        /* resource file handle     */
  83. MLOCAL    WORD    d_hndl = -1;        /* definition file handle     */
  84. MLOCAL    WORD    r2_hndl = -1;        /* output resource handle    */
  85. MLOCAL    WORD    d2_hndl = -1;        /* output definition handle    */
  86.  
  87. MLOCAL    LONG    f_err;            /* file error            */
  88. MLOCAL    BYTE    *head;            /* location of buffer        */
  89. MLOCAL    LONG    buff_size;        /* size of buffer        */
  90. MLOCAL    BYTE    buff[20];        /* def file work area        */
  91. MLOCAL    UWORD    img_offset, addr;    /* for image fixup        */
  92. MLOCAL    WORD    img_odd;        /* image fixup needed?        */
  93. MLOCAL    GRECT    prog_rect;        /* rectangle for prog indicator */
  94.  
  95. /*------------------------------*/
  96. /*    swap_bytes         */
  97. /*------------------------------*/
  98.     VOID
  99. swap_bytes(where, len)
  100.     BYTE    *where;
  101.     WORD    len;
  102.     {
  103.     BYTE    swap;
  104.  
  105.     for (; len > 0; len -= 2)
  106.         {
  107.         swap = *where;
  108.         *where = *(where + 1);
  109.         *(where + 1) = swap;
  110.         where += 2;
  111.         }
  112.     }
  113.  
  114. /*------------------------------*/
  115. /*    swap_words         */
  116. /*------------------------------*/
  117.     VOID
  118. swap_words(where, len)
  119.     WORD    *where;
  120.     WORD    len;
  121.     {
  122.     UWORD    swap;
  123.  
  124.     for (; len > 0; len -= 4)
  125.         {
  126.         swap = *where;
  127.         *where = *(where + 1);
  128.         *(where + 1) = swap;
  129.         where += 2;
  130.         }
  131.     }
  132.  
  133. /*------------------------------*/
  134. /*    swap_images         */
  135. /*------------------------------*/
  136.     VOID
  137. swap_images()
  138.     {
  139.     BITBLK    *where;
  140.     ICONBLK *where2;
  141.     BYTE    *taddr;
  142.     WORD    num;
  143.     WORD    wb, hl;
  144.  
  145.     where = (BITBLK *) (head + ((RSHDR *) head)->rsh_bitblk);
  146.     num = ((RSHDR *) head)->rsh_nbb;
  147.     for (; num--; where++)
  148.         {
  149.         taddr = where->bi_pdata;
  150.         wb = where->bi_wb;
  151.         hl = where->bi_hl;
  152.         if ((LONG) taddr != -1L)
  153.             {
  154.             if (img_odd)
  155.                 where->bi_pdata = ++taddr;
  156.             swap_bytes(head + taddr, wb * hl);
  157.             }
  158.         }
  159.  
  160.     where2 = (ICONBLK *) (head + ((RSHDR *) head)->rsh_iconblk);
  161.     num = ((RSHDR *) head)->rsh_nib;
  162.     for (; num--; where2++)
  163.         {
  164.         wb = (where2->ib_wicon + 7) >> 3;
  165.         hl = where2->ib_hicon;
  166.         taddr = where2->ib_pdata;
  167.         if ((LONG) taddr != -1L)
  168.             {
  169.             if (img_odd)
  170.                 where2->ib_pdata = ++taddr;
  171.             swap_bytes(head + taddr, wb * hl);
  172.             }
  173.         taddr = where2->ib_pmask;
  174.         if ((LONG) taddr != -1L)
  175.             {
  176.             if (img_odd)
  177.                 where2->ib_pmask = ++taddr;
  178.             swap_bytes(head + taddr, wb * hl);
  179.             }
  180.         }
  181.     }
  182.  
  183. /*------------------------------*/
  184. /*    swap_trees         */
  185. /*------------------------------*/
  186.     VOID
  187. swap_trees()
  188.     {
  189.     BYTE    *where;
  190.     WORD    size;
  191.  
  192.     where = head + ((RSHDR *) head)->rsh_trindex;
  193.     size = ((RSHDR *) head)->rsh_ntree * sizeof(LONG);
  194.     swap_bytes(where, size);
  195.     swap_words((WORD *) where, size);
  196.     }
  197.  
  198. /*------------------------------*/
  199. /*    swap_objs         */
  200. /*------------------------------*/
  201.     VOID
  202. swap_objs()
  203.     {
  204.     OBJECT    *where;
  205.     WORD    num;
  206.  
  207.     where = (OBJECT *) (head + ((RSHDR *) head)->rsh_object);
  208.     num = ((RSHDR *) head)->rsh_nobs;
  209.     swap_bytes((BYTE *) where, num * sizeof(OBJECT));
  210.     for (; num--; where++)
  211.         swap_words((WORD *) &where->ob_spec, sizeof(LONG));
  212.     }
  213.  
  214. /*------------------------------*/
  215. /*    swap_teds         */
  216. /*------------------------------*/
  217.     VOID
  218. swap_teds()
  219.     {
  220.     TEDINFO    *where;
  221.     WORD    num;
  222.  
  223.     where = (TEDINFO *) (head + ((RSHDR *) head)->rsh_tedinfo);
  224.     num = ((RSHDR *) head)->rsh_nted;
  225.     swap_bytes((BYTE *) where, num * sizeof(TEDINFO));
  226.     for (; num--; where++)
  227.         {
  228.         swap_words((WORD *) &where->te_ptext, sizeof(LONG));
  229.         swap_words((WORD *) &where->te_ptmplt, sizeof(LONG));
  230.         swap_words((WORD *) &where->te_pvalid, sizeof(LONG));
  231.         }
  232.     }
  233.  
  234. /*------------------------------*/
  235. /*    swap_ibs         */
  236. /*------------------------------*/
  237.     VOID
  238. swap_ibs()
  239.     {
  240.     ICONBLK    *where;
  241.     WORD    num;
  242.  
  243.     where = (ICONBLK *) (head + ((RSHDR *) head)->rsh_iconblk);
  244.     num = ((RSHDR *) head)->rsh_nib;
  245.     swap_bytes((BYTE *) where, num * sizeof(ICONBLK));
  246.     for (; num--; where++)
  247.         {
  248.         swap_words((WORD *) &where->ib_pdata, sizeof(LONG));
  249.         swap_words((WORD *) &where->ib_pmask, sizeof(LONG));
  250.         swap_words((WORD *) &where->ib_ptext, sizeof(LONG));
  251.         }
  252.     }
  253.  
  254. /*------------------------------*/
  255. /*    swap_bbs         */
  256. /*------------------------------*/
  257.     VOID
  258. swap_bbs()
  259.     {
  260.     BITBLK    *where;
  261.     WORD    num;
  262.  
  263.     where = (BITBLK *) (head + ((RSHDR *) head)->rsh_bitblk);
  264.     num = ((RSHDR *) head)->rsh_nbb;
  265.     swap_bytes((BYTE *) where, num * sizeof(BITBLK));
  266.     for (; num--; where++)
  267.         swap_words((WORD *) &where->bi_pdata, sizeof(LONG));
  268.     }
  269.  
  270. /*------------------------------*/
  271. /*    swap_fstr         */
  272. /*------------------------------*/
  273.     VOID
  274. swap_fstr()
  275.     {
  276.     BYTE    *where;
  277.     WORD    size;
  278.  
  279.     where = head + ((RSHDR *) head)->rsh_frstr;
  280.     size = ((RSHDR *) head)->rsh_nstring * sizeof(LONG);
  281.     swap_bytes(where, size);
  282.     swap_words((WORD *) where, size);
  283.     }
  284.  
  285. /*------------------------------*/
  286. /*    swap_fimg         */
  287. /*------------------------------*/
  288.     VOID
  289. swap_fimg()
  290.     {
  291.     LONG    where;
  292.     WORD    size;
  293.  
  294.     where = head + ((RSHDR *) head)->rsh_frimg;
  295.     size = ((RSHDR *) head)->rsh_nimages * sizeof(LONG);
  296.     swap_bytes(where, size);
  297.     swap_words((WORD *) where, size);
  298.     }
  299.  
  300. /*------------------------------*/
  301. /*    close_files         */
  302. /*------------------------------*/
  303.     VOID
  304. close_files()
  305.     {
  306.     if (r_hndl != -1)
  307.         Fclose(r_hndl);
  308.     if (d_hndl != -1)
  309.         Fclose(d_hndl);
  310.     if (r2_hndl != -1)
  311.         Fclose(r2_hndl);
  312.     if (d2_hndl != -1)
  313.         Fclose(d2_hndl);
  314.     r_hndl = d_hndl = r2_hndl = d2_hndl = -1; 
  315.     }
  316.  
  317. /*------------------------------*/
  318. /*    do_conv         */
  319. /*------------------------------*/
  320.     WORD
  321. do_conv()
  322.     {
  323.     BYTE    *str; 
  324.     LONG    size;
  325.     WORD    reply, nsym;
  326.  
  327.     r_file[0] = '\0';
  328.  
  329.     if (!get_file(old_rsc, r_file))
  330.         return;
  331.     if ((r_hndl = open_file(r_file)) == -1)
  332.         return;
  333.     if (conv_def)
  334.         {
  335.         new_ext(r_file, d_file, old_def);
  336.         FOREVER {
  337.             d_hndl = (WORD) Fopen(d_file, 0);
  338.             if (d_hndl >= 0)
  339.                 break;
  340.             rsrc_gaddr(R_STRING, NODEF, &str);
  341.             reply = form_alert(1, str);
  342.             if (reply == 3)
  343.                 {
  344.                 close_files();
  345.                 return;
  346.                 }
  347.             if (reply == 1)
  348.                 {
  349.                 conv_def = FALSE;
  350.                 break;
  351.                 }
  352.                         /* if (reply == 2) */
  353.             if (!get_file(old_def, d_file))
  354.                 break;
  355.             }
  356.         }
  357.  
  358.     graf_mouse(HOUR_GLASS, 0x0L);
  359.     beg_prog(&prog_rect)